package team.fivez.defaultmanage.dao.Impl;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import team.fivez.defaultmanage.dao.CustomerDao;
import team.fivez.defaultmanage.domain.Customer;

import javax.annotation.Resource;


@Repository
public class CustomerDaoImpl implements CustomerDao {

    @Resource
    private JdbcTemplate jdbcTemplate;

    //根据用户名查询用户信息
    @Override
    public Customer getCustomerByName(String Name) {
        String sql = "select * from customer where customer_name=?";

        return jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<>(Customer.class),Name);
    }

    @Override
    public Integer selectCountByName(String Name) {
        String sql="select count(*) from customer where customer_name=?";
        return jdbcTemplate.queryForObject(sql, Integer.class,Name);
    }

    @Override
    public int updateStatusByCustomerName(String customerName, int status) {
        String sql="update customer set default_status=? where customer_name=?";
        return jdbcTemplate.update(sql,status,customerName);
    }
}
